import ajax from '../js/ajax';

const form = document.forms[0];

form.onsubmit = function (e) {
    e.preventDefault();
    let newPwd = form.pwd1.value;
    let repPwd = form.pwd2.value;
    if (newPwd != repPwd) {
        alert('两次密码输入不一致');
        return false;
    }

    ajax('post', '/api/admin/modifyPwd', { newPwd })
        .then(({ flag, msg }) => {
            if (flag) {
                alert(msg);
                localStorage.removeItem('token');
                top.location.assign('login.html');
            }
        })
        .catch(err => {
            alert('服务器忙，请稍后再试');
        })
}